#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"

//GPIO pins define here 
#define LED_TASK_GPIO1 7
#define LED_TASK_GPIO2 8
#define LED_INTERVAL_TIME 30
#define LED_TASK_STACK_SIZE 512
#define LED_TASK_PRIO 25

static void LedTask1(void)
{
    while (1)
    {
        //One led is always on
        IoTGpioSetOutputVal(LED_TASK_GPIO1,1);

        // //The other led is blinkling
        IoTGpioSetOutputVal(LED_TASK_GPIO2,1);
        usleep(500*1000);
        
        IoTGpioSetOutputVal(LED_TASK_GPIO2,0);
        usleep(500*1000);

    }
}

static void LedExampleEntry(void)
{
    //CMSIS 库 把常见的RTOS接口做封装,让代码更方便移植
    osThreadAttr_t attr;
    //Init the GPIO pins and the directions
    IoTGpioInit(LED_TASK_GPIO1);
    IoTGpioSetDir(LED_TASK_GPIO1,IOT_GPIO_DIR_OUT);
    IoTGpioInit(LED_TASK_GPIO2);
    IoTGpioSetDir(LED_TASK_GPIO2,IOT_GPIO_DIR_OUT);

 
    attr.name = "LedTask1";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = LED_TASK_STACK_SIZE;
    attr.priority = LED_TASK_PRIO;
    if (osThreadNew((osThreadFunc_t)LedTask1, NULL, &attr) == NULL) {
        printf("[LedExample] Falied to create LedTask1!\n");
    }
}

SYS_RUN(LedExampleEntry);
